﻿using Api.Common;
using Microsoft.AspNet.SignalR;
using Microsoft.AspNet.SignalR.Hubs;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Web;

namespace PushManager.Web
{
    public class ErrorhandlingModule : HubPipelineModule
    {
        protected override void OnIncomingError(ExceptionContext exceptionContext, IHubIncomingInvokerContext invokerContext)
        {
            Debug.WriteLine("=> Exception" + exceptionContext.Error.Message + Environment.NewLine + "=> Hub" + invokerContext.Hub);
            if (exceptionContext.Error.InnerException != null)
            {
                Debug.Write("=> innder Exception" + exceptionContext.Error.InnerException.Message + Environment.NewLine + "=> Hub" + invokerContext.Hub);
            }
            LogHelper.WriteErrorLog(JsonConvert.SerializeObject(exceptionContext.Error));
            //GlobalHost.ConnectionManager.GetHubContext<ChatHub>().Clients.All.error(exceptionContext.Error);
            //exceptionContext.Result = null;
            
            
            base.OnIncomingError(exceptionContext, invokerContext);
        }
    }
}